﻿using System;
using System.Collections.Generic;

namespace DataManage
{
    public static class Collection
    {
        #region 常量   
        public const int STATUS_ERR = 0;
        public const int STATUS_OK = 1;
        public const uint STATUS_ONLINE = 2;//设备在线
        public const uint STATUS_OFFLINE = 3;//设备离线
        public const int CAN_MAX_DLEN = 8;
        public const int LIN_MAX_DLEN = 8;
        /* CAN FD payload length and DLC definitions according to ISO 11898-7 */
        public const int CANFD_MAX_DLC = 15;
        public const int CANFD_MAX_DLEN = 64;

        public const uint CAN_EFF_FLAG = 0x80000000U; /* EFF/SFF is set in the MSB */
        public const uint CAN_RTR_FLAG = 0x40000000U; /* remote transmission request */
        public const uint CAN_ERR_FLAG = 0x20000000U; /* error message frame */
        public const uint CAN_ID_FLAG = 0x1FFFFFFFU; /* id */
        #endregion

        /// <summary>
        /// CAN供应商
        /// </summary>
        public static Dictionary<CANSupplierType, string> CANSuppliers = new Dictionary<CANSupplierType, string>()
        {
            { CANSupplierType.ZLG, "周立功" },
        };

        /// <summary>
        /// CAN类型
        /// </summary>
        public static Dictionary<ZLGCANType, string> ZLGCANTypes = new Dictionary<ZLGCANType, string>()
        {
            { ZLGCANType.USBCAN1, "USBCAN1" },
            { ZLGCANType.USBCAN2, "USBCAN2" },
            { ZLGCANType.USBCANFD_200U, "USBCANFD_200U" },
            { ZLGCANType.USBCANFD_100U, "USBCANFD_100U" },
            { ZLGCANType.USBCANFD_MINI, "USBCANFD_MINI" },
            { ZLGCANType.PCIECANFD_100U, "PCIECANFD_100U" },
            { ZLGCANType.PCIECANFD_200U, "PCIECANFD_200U" },
            { ZLGCANType.PCIECANFD_200U_EX, "PCIECANFD_200U_EX" },
            { ZLGCANType.PCIECANFD_400U, "PCIECANFD_400U" },
            { ZLGCANType.USBCAN_E_U, "USBCAN_E_U" },
            { ZLGCANType.USBCAN_2E_U, "USBCAN_2E_U" },
        };

        /// <summary>
        /// 波特率
        /// </summary>
        public static Dictionary<string, uint> KBaudRate = new Dictionary<string, uint>() 
        {
           { "1Mbps",1000000 },
           { "800kbps",800000 },
           { "500kbps",500000 },
           { "250kbps",250000 },
           { "125kbps",125000 },
           { "100kbps",100000 },
           { "50kbps",50000 },
        };
        /// <summary>
        /// CAN索引
        /// </summary>
        public static List<int> CANIndex = new List<int>() { 0, 1, 2, 3 };
        /// <summary>
        /// Channel索引
        /// </summary>
        public static List<int> ChannelIndex = new List<int>() { 0, 1, 2, 3 };
        /// <summary>
        /// ZLGCAN错误码
        /// </summary>
        public static Dictionary<uint, string> ZLGErrorType = new Dictionary<uint, string>()
        {
            { 0x0001, "CAN控制器内部FIFO溢出" },
            { 0x0002, "CAN控制器错误报警" },
            { 0x0004, "CAN控制器消极错误" },
            { 0x0008, "CAN控制器仲裁丢失" },
            { 0x0010, "CAN控制器总线错误" },
            { 0x0020, "CAN控制器总线关闭" },
            { 0x0040, "CAN缓存溢出" },
            { 0x0100, "设备已经打开" },
            { 0x0200, "打开设备错误" },
            { 0x0400, "设备没有打开" },
            { 0x0800, "缓冲区溢出" },
            { 0x1000, "此设备不存在" },
            { 0x2000, "装载动态库失败" },
            { 0x4000, "执行命令失败错误码" },
            { 0x8000, "内存不足" },
            { uint.MinValue, "CAN通讯异常"}
        };
        /// <summary>
        /// 固件升级设备地址
        /// </summary>
        public static Dictionary<byte, string> DeviceAdress = new Dictionary<byte, string>()
        {
            //{ 0x80, "上位机" },
            { 0x8E, "MBMU" },
            { 0x7E, "SBMU" },
            { 0x5E, "VCMU" },
            { 0x4E, "TCMU" },
        };
        /// <summary>
        /// 芯片型号
        /// </summary>
        public static Dictionary<byte, string> STMType = new Dictionary<byte, string>()
        {
            { 0x01, "STM32F103RC" },
            { 0x02, "MC9S12GA240CLH" },
            { 0x03, "STM32F103RE" },
            { 0x04, "STM32F407ZG" },
            { 0x05, "ST32G473CET" },
        };

        #region MBMU|SBMU|VCMU|TCMU|HMU 资源字段
        public static Dictionary<int, string> SystemRunStateDescription = new Dictionary<int, string>()
        {
            { 1, "未接入" },
            { 2, "启动接入" },
            { 3, "已连接" },
            { 4, "下电中" },
            { 9, "接入故障" },
        };
        public static Dictionary<int, string> ChgDchStateDescription = new Dictionary<int, string>()
        {
            { 1, "未连接" },
            { 2, "放空" },
            { 3, "放电" },
            { 4, "充电" },
            { 5, "充满" },
            { 6, "空闲" },
        };
        public static Dictionary<int, string> SystemFaultStateDescription = new Dictionary<int, string>()
        {
            { 0, "正常" },
            { 1, "预警" },
            { 2, "告警" },
            { 3, "保护" },
        };
        /// <summary>
        /// 继电器状态、干节点状态
        /// </summary>
        public static Dictionary<int, string> RelayStatusDescription = new Dictionary<int, string>()
        {
            { 0, "断开" },
            { 1, "闭合" },
            { 2, "粘连" },
            { 3, "失效" },
        };
        public static Dictionary<int, string> SystemCtlCmdStateDescription = new Dictionary<int, string>()
        {
            { 0, "无效" },
            { 1, "有效" },
        };
        public static Dictionary<int, string> CellBalancedDescription = new Dictionary<int, string>()
        {
            { 0, "未均衡" },
            { 1, "均衡" },
            { 3, "无效" },
        };
        public static Dictionary<int, string> WakeUpModeDescription = new Dictionary<int, string>()
        {
            { 0x00, "未唤醒" },
            { 0x01, "唤醒" },
            { 0x11, "无效" },
        };
        /// <summary>
        /// 电源状态描述
        /// </summary>
        public static Dictionary<int, string> PowerStateDescription = new Dictionary<int, string>()
        {
            { 0x00, "电源关闭" },
            { 0x01, "电源输出" },
        };
        public static Dictionary<int, string> DOControlStateDescription = new Dictionary<int, string>()
        {
            { 0x00, "低电平输出" },
            { 0x01, "高电平输出" },
            { 0x10, "PWM波输出" },
        };
        public static Dictionary<int, string> DIControlStateDescription = new Dictionary<int, string>()
        {
            { 0x00, "输入为低" },
            { 0x01, "输入为高" },
            { 0x10, "输入为PWM波信号" },
        };
        /// <summary>
        /// VCMU AFE电芯均衡状态
        /// </summary>
        public static Dictionary<int, string> AFEBalanceStateDescription = new Dictionary<int, string>()
        {
            { 0x00, "关闭" },
            { 0x01, "充电均衡已开启" },
            { 0x02, "放电均衡已开启" },
        };
        /// <summary>
        /// 从板激活信号
        /// </summary>
        public static Dictionary<Int64, string> ActivationSignal = new Dictionary<Int64, string>()
        {
            { 0xFFFFFFFF, "未配置" },
            { 0xFFFFFEFF, "已配置" },//待修改
        };
        #endregion

    }
}
